<template>
  <div>
    <!-- 索赔结算单查询-编辑页面 -->
    <BreakSpace label="结算单汇总信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="formPanel" :list="formList" :cols="3" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
    <div style="padding-top: 2rem;"></div>
    <BreakSpace label="结算单列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :is-select-column="false"
      :isSelectColumn="false"
      :isPagination = false
      height="auto"
    >
    </FilterTable>
    <div style="padding-top: 3rem;"></div>
    <BreakSpace label="审核列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table1"
      :columns="columns1"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :is-select-column="false"
      :isSelectColumn="false"
      :isPagination = false
      height="auto"
    >
    </FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <div style="padding-top: 3rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    <Drawer :visible.sync="chakanFlag" :title="'结算单详情'" destroyOnClose width="60%" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <showDetail @close="chakanFlag=false" :rowData="rowDate"></showDetail>
    </Drawer>
  </div>
</template>
<script>
  import {  getPartType,quyrPSettleSum } from '@/api/claim/factory/ClaimAccountSummarySubmit';
  import { isFormEmpty } from '@/utils/index';
  import { dictionary } from '@/utils/dictMixin';
  import showDetail from "../ClaimStatementQueryFactory/showDetail";
  export default {
    mixins: [dictionary],
    props: ['rowData'],
    components: {
      showDetail
    },
    data() {
      return {
        dataList: [],
        editRow: {},
        yuanIds:'' ,
        visible: false,
        jiesuandanFlag: false,
        visibleDrawer: false,
        jiesuansum: 0,
        fapiaozhangshusum: 0,
        collapse: false,
        infoId: null,
        flterValue: {}, //参数
        columns: this.creatHeader(),
        columns1: this.creatHeader1(),
        fetchParams: {}, //ipa 接口
        selectedRows: [], //选中经销商
        formList: this.createFormList(),
        saveData: null,
        rowDate:null,
        chakanFlag:false
      };
    },
    async created() {
      await this.chuqi();
      await this.chuqi2();
      await this.getDetailFun(this.rowData.sumId);
    },
    methods: {
      async getDetailFun(val) {
        let res= await quyrPSettleSum(val);
        this.editRow = res.data;

        this.jiesuansum=this.editRow.invoiceAmount;
        this.fapiaozhangshusum=this.editRow.invoiceSheets;
        //为form赋值
        for (let i in res.data) {
          this.formList.map(x => {
            if (x.fieldName == i) {
              x.initialValue = res.data[i];
            }
          });
        }
        //为table赋值
        if (200 == res.resultCode) {
          let data = res.data;
          if (isFormEmpty(data)) {
            data = {};
          }
          let records = data.batchList;
          if (isFormEmpty(records)) {
            records = [];
          }
          this.$refs.table.$refs.pageTable.EXECUTE_INSERT(records);
          //取出ids
          let ids1 = [];
          this.$refs.table.$refs.pageTable.list.map(x => {
            ids1.push(x.dtlId);
          });
          let ids = '';
          ids1.map(x => {
            ids += x + ','
          });
          this.yuanIds = ids;
          console.log(this.yuanIds);
        }
        if (200 == res.resultCode) {
          let data = res.data;
          if (isFormEmpty(data)) {
            data = {};
          }
          let records1 = data.logList;
          if (isFormEmpty(records1)) {
            records1 = [];
          }
          this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(records1);
        }

      },
      //索赔车辆分类
      async chuqi2() {
        // const res = await getPartType({ type: 5543 });
        // if (res.resultCode == 200) {
        //   this.formList.find(x => x.fieldName == 'sumType').initialValue = '';
        //   this.formList.find(x => x.fieldName == 'sumType').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        // }
      },
      //结算单状态
      async chuqi() {
        // const res = await getPartType({ type: 5547 });
        // if (res.resultCode == 200) {
        //   this.formList.find(x => x.fieldName == 'sumStatus').initialValue = '';
        //   this.formList.find(x => x.fieldName == 'sumStatus').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        // }
      },
      formChangeHandle(val) {
        console.log(val);
        this.saveData = val;
      },
      //搜索获取数据
      changeHandle(val) {
        this.fetchParams = val;
        console.log(val);
      },
      //结算单计算
      jiesuandansave(val) {
        this.$refs.table.$refs.pageTable.EXECUTE_INSERT(val);
        //总金额
        let jiesuanjine = 0;
        this.$refs.table.$refs.pageTable.list.map(x => {
          jiesuanjine += Number(x.settleSum);
        });
        this.formList.map(x => {
          if ('invoiceAmount' == x.fieldName) {
            x.initialValue = Number(jiesuanjine);
          }
        });
        this.jiesuansum=jiesuanjine;
        //发票张数
        let fapiaozhangshu = 0;
        this.$refs.table.$refs.pageTable.list.map(x => {
          fapiaozhangshu += Number(x.invoiceSheets);
        });
        this.formList.map(x => {
          if ('invoiceSheets' == x.fieldName) {
            x.initialValue = Number(fapiaozhangshu);
          }
        });
        this.fapiaozhangshusum=fapiaozhangshu;
        this.jiesuandanFlag = false;
      },
      suopeidanclose() {
        this.suopeidanFlag = false;
      },
      jiesuandanadd() {
        this.jiesuandanFlag = true;
      },
      jiesuandanclose() {
        this.jiesuandanFlag = false;
      },
      //选中
      selectChange(rows) {
        this.selectedRows = rows;
      },
      //取消操作
      closeDialog() {
        this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
      },
      chooseOrderNo() {
        this.visible = true;
      },
      chakan(val) {
        this.rowDate = val;
        this.chakanFlag = true;
      },
      add() {},
      createFormList() {
        return [
          {
            type: 'INPUT',
            label: '结算汇总单号',
            fieldName: 'sumNo',
            initialValue: '',
            disabled:true
          },
          {
            type: 'SELECT',
            label: '索赔车辆分类',
            fieldName: 'sumType',
            rules: [{ required: true, message: '请选择索赔车辆分类', trigger: 'blur' }],
            initialValue: '',
            disabled:true,
            itemList:this.createDictList('5543'),
          },
          {
            type: 'SELECT',
            label: '单据状态',
            fieldName: 'sumStatus',
            initialValue: '',
            itemList:this.createDictList('5547'),
            disabled:true
          }, {
            type: 'INPUT',
            label: '发票张数',
            fieldName: 'invoiceSheets',
            disabled:true,
            initialValue: '',
          }, {
            type: 'INPUT',
            label: '开票总金额',
            fieldName: 'invoiceAmount',
            disabled:true,
            initialValue: '',
          },{
            type: 'DATE_TIME',
            label: '提交时间',
            dateFormat: 'yyyy-MM-dd',
            disabled:true,
            fieldName: 'applyDate',
            initialValue: '',
          },
          {
            type: 'TEXT_AREA',
            label: '开票备注',
            selfCols: '3',
            fieldName: 'invoiceRemarks',
            disabled:true,
            initialValue: '',
            placeholder: '开票备注...',
          }
        ];
      },
      //结算单列表
      creatHeader() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            fixed: 'left',
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '操作',
            dataIndex: 'column-action',
            width: 100,
            render: (props) => {
              return (
                <div style="text-align:center">
                  <multiuse-button type="text" onClick={() => this.chakan(props.row)} >
                    详情
                  </multiuse-button>
                </div>
              );
            },
          },
          { title: '经销商代码', dataIndex: 'dealerCode', sorter: true },
          { title: '经销商名称', dataIndex: 'dealerName', sorter: true },
          { title: '结算批次单号', dataIndex: 'batchNo', sorter: true },
          { title: '索赔单数', dataIndex: 'claimNum', sorter: true },
          { title: '发票张数', dataIndex: 'invoiceSheets', sorter: true },
          { title: '结算金额', dataIndex: 'settleSum', sorter: true },
          { title: '索赔金额', dataIndex: 'claimSum', sorter: true },
          { title: '考核金额', dataIndex: 'assessSum', sorter: true },
          // { title: '税额', dataIndex: 'settleStatusStr', sorter: true },
          { title: '工时费（元）', dataIndex: 'labourAmount', sorter: true },
          { title: '配件费用（元）', dataIndex: 'partAmount', sorter: true },
          { title: '附加费（元）', dataIndex: 'addAmount', sorter: true },
          // { title: '让渡数量', dataIndex: 'rangDuNum', sorter: true },
          // { title: '让渡金额', dataIndex: 'rangDuAmount', sorter: true },
          // { title: '正常索赔', dataIndex: 'zhengChangAmount', sorter: true },
          // { title: '喷漆索赔', dataIndex: 'penQiAmount', sorter: true }
        ];
      },
      //审核列表
      creatHeader1() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          { title: '操作人', dataIndex: 'checkBy', sorter: true },
          { title: '操作时间', dataIndex: 'checkAt', sorter: true },
          { title: '操作后状态', dataIndex: 'statusStr', sorter: true },
          { title: '审核原因', dataIndex: 'checkRemarks', sorter: true }
        ];
      }
    }
  };
</script>
<style lang="less" scoped></style>
